I tried setting up Jenkins in EC2 for CICD on AWS Using Cloudformation
Hello
I am aayush
Creating build functions from open source tools rather than code builds has its own advantages and disadvantages
So I will list how I used jenkins on my ec2 instance and the advantages and disadvantages of using jenkins against the aws CICD service
Advantages of using Jenkins on the AWS CICD service include
- Flexibility: Jenkins is a highly configurable and customizable tool that can accommodate a wide range of use cases and integration options.
- Community support: Jenkins has a large and active community, meaning there is a wealth of resources, plug-ins, and tutorials available to users.
- Open source: Jenkins is open source software, which means it is free to use and can be modified to suit specific needs.
Disadvantages of Jenkins over the AWS CICD service include
- Complexity: Jenkins can be complex to set up and maintain, especially for users with limited technical expertise.
- Scalability: Jenkins may not be able to handle large CI/CD pipeline workloads as well as the more specialized AWS CICD service.
- Security: Jenkins may not have the same level of built-in security features as some specialized AWS CICD services.
I Tried
Creating Infrastructure Cloudformation template for creating Ec2 resources.
Update your amazon linux 2 AMI ID to the appropriate region.
You will also need to create a name for the key pair and update it in the template.
AWSTemplateFormatVersion: '2010-09-09' Resources: JenkinsInstance: Type: 'AWS::EC2::Instance' Properties: InstanceType: t2.micro ImageId: ami-0bba69335379e17f8 SecurityGroupIds: - !Ref JenkinsSecurityGroup UserData: "Fn::Base64": !Sub | #!/bin/bash # setup Jenkins on EC2 sudo yum update -y sudo wget -O /etc/yum.repos.d/jenkins.repo \ https://pkg.jenkins.io/redhat-stable/jenkins.repo sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key sudo yum upgrade sudo amazon-linux-extras install java-openjdk11 -y sudo yum install jenkins -y sudo systemctl enable jenkins sudo systemctl start jenkins KeyName: TokyoPersonal JenkinsSecurityGroup: Type: 'AWS::EC2::SecurityGroup' Properties: GroupDescription: Allow traffic to Jenkins SecurityGroupIngress: - IpProtocol: tcp FromPort: 8080 ToPort: 8080 CidrIp: 0.0.0.0/0 - IpProtocol: tcp FromPort: 22 ToPort: 22 CidrIp: 0.0.0.0/0 Outputs: JenkinsURL: Description: The URL for the Jenkins instance Value: !Sub "http://${JenkinsInstance.PublicIp}:8080" Export: Name: JenkinsURL
The URL will appear in the output section of the Cloudformation in management console. Or Open a browser and hit the public IP and port 8080.
http://xx.xx.xx.xx/xx:8080
Configuring Jenkins
As soon as you open the link, the following screen will appear for the first time only.
The following screen will appear and you can connect in any way you wish. In this case, we used Ec2 Instance Connect, but we recommend using Session Manager.
After connecting, use the cat command to obtain the password.
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Copy and paste the output into Unlock jenkins Screen.
In this case, we installed the recommended plug-ins.
It will install all necessary plugins you will see a list of plugins in the image below.
Then add your username, password, full name, and email address, and click "Save & Continue"
Confirm the Jenkins Url and click Save and Finish.
You are ready to use Jenkins. Click Start using Jenkins.
The dashboard will appear
Conclusion:
Now that the infrastructure has been successfully created, all that remains is to optimize and further configure jenkins. We will write more about other settings in the future.